# A GUI for the report generator utility

import wx

class reportGeneratorFrame(wx.Frame):
	def __init__(self, parent, header, componentList, *args, **kwds):
		# Save the header and parent
		self.parent = parent
		self.header = header
		
		# Get the basic widgets created
		kwds["style"] = wx.DEFAULT_FRAME_STYLE
		wx.Frame.__init__(self, *args, **kwds)
		self.backgroundPannel = wx.Panel(self, -1)
		self.checkSizer_staticbox = wx.StaticBox(self.backgroundPannel, -1, "Include")
		self.generateButton = wx.Button(self.backgroundPannel, -1, "Generate Report")
		
		# Put the in the header
		self.headerLabel = wx.StaticText(self.backgroundPannel, -1, self.header)
		
		# A list that will house all of the checkboxes
		self.checkList = []
		
		# Put in the checkboxes
		for component in componentList:
			newCheckBox = wx.CheckBox(self.backgroundPannel, -1, component)
			self.checkList.append(newCheckBox)
		
		# Bind the button
		self.generateButton.Bind(wx.EVT_KEY_DOWN, self.parent.generateReport)

		self.__set_properties()
		self.__do_layout()

	def __set_properties(self):
		# Set the title and header font
		self.SetTitle(self.header)
		self.headerLabel.SetFont(wx.Font(18, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))

	def __do_layout(self):
		# Put in the known layout
		containerSizer = wx.BoxSizer(wx.VERTICAL)
		mainSizer = wx.FlexGridSizer(3, 1, 0, 0)
		mainSizer.Add(self.headerLabel, 0, 0, 0)
		checkSizer = wx.StaticBoxSizer(self.checkSizer_staticbox, wx.VERTICAL)
		
		for checkbox in self.checkList: checkSizer.Add(checkbox, 0, 0, 0)
		
		# Finish it off
		mainSizer.Add(checkSizer, 1, wx.EXPAND, 0)
		mainSizer.Add(self.generateButton, 0, 0, 0)
		self.backgroundPannel.SetSizer(mainSizer)
		containerSizer.Add(self.backgroundPannel, 1, wx.EXPAND, 0)
		self.SetSizer(containerSizer)
		containerSizer.Fit(self)
		self.Layout()
		
def createReportGeneratorWindow(parent, header, fields):
	reportGeneratorWindow = reportGeneratorFrame(parent, header, fields, None, -1, "")
	reportGeneratorWindow.Show()
	return reportGeneratorWindow
